import pandas as pd
import numpy as np
import collections



def pd_demo():
    df = pd.DataFrame(
        np.random.random(size=(100,4)),
        columns=list('ABCD')
    )
    # print(df)     iterrows()
    for index,row in df.iterrows():
        print(index,row)

    # 2. df.itertuples()
    for row in df.itertuples():
        # print(row)
        print(row.index, row.A, row.B, row.C, row.D)
    print("-----------------------------------------------------------------------")
    res = collections.defaultdict(int)
    for row in df.itertuples():
        print(row)

    # 3. for+zip
    # 既不需要类型检查，也不需要构建namedtuple
    # 缺点是需要挨个指定变量
    for a,b in zip(df['A'],df['B']):
        print(a,b)








if __name__ == "__main__":
    pd_demo()